package com.lanou.tipsy.tools.custom;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.lanou.tipsy.R;

/**
 * Created by dllo on 15/10/29.
 */
public class ThemePopupWindow extends PopupWindow {

    private Button blue,red,orange,yellow,green,black,purple,feng;
    private View menuView;

    public ThemePopupWindow(Activity context,View.OnClickListener itemsOnClick){
        super(context);
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        menuView = inflater.inflate(R.layout.theme_menu,null);
        blue = (Button) menuView.findViewById(R.id.blue);
        red = (Button) menuView.findViewById(R.id.red);
        orange = (Button) menuView.findViewById(R.id.orange);
        yellow = (Button) menuView.findViewById(R.id.yellow);
        green = (Button) menuView.findViewById(R.id.green);
        black = (Button) menuView.findViewById(R.id.black);
        purple = (Button) menuView.findViewById(R.id.purple);
        feng = (Button) menuView.findViewById(R.id.feng);
        /*
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();;
            }
        });*/
        blue.setOnClickListener(itemsOnClick);
        red.setOnClickListener(itemsOnClick);
        orange.setOnClickListener(itemsOnClick);
        yellow.setOnClickListener(itemsOnClick);
        green.setOnClickListener(itemsOnClick);
        black.setOnClickListener(itemsOnClick);
        purple.setOnClickListener(itemsOnClick);
        feng.setOnClickListener(itemsOnClick);

        //设置SelectPicPopupWindow的View
        this.setContentView(menuView);
        //设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(LinearLayout.LayoutParams.FILL_PARENT);
        //设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);

        menuView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int height = menuView.findViewById(R.id.themeMenu).getTop();
                int y = (int) event.getY();
                if (event.getAction()==MotionEvent.ACTION_UP){
                    if (y<height){
                        dismiss();
                    }
                }
                return true;
            }
        });
    }

}
